/**
@Description  请填写文件描述（需要改）
@author: freedom
@date: 2021/5/25
@note:
**/
package service

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/utils/es"
)

// 新增文档
func CreateKnowledge(knowledge model.SysKnowledge) error {
	_, err := es.AddDocument(global.INDEX, &knowledge)
	return err
}

// 根据标题查询
func QueryKnowledge(title string) string {
	id, _ := es.QueryDocumentByTitle(global.INDEX, title)
	return id
}

//根据ID更新文档
func UpdateDocument(id string, documentMap map[string]interface{}) error {
	err := es.UpdateDocument(global.INDEX, id, documentMap)
	return err

}

// 根据条件查询
func QueryKnowledgesBySearch(info request.SysKnowledgeSearch) (list interface{}, num int64, err error) {
	sysKnowledges, total, err := es.QueryDocumentBySearchInfo(global.INDEX, info)
	return sysKnowledges, total, err
}

// 根据条件返回建议信息

func QuerySuggestByTitle(info model.SysKnowledge) ([]string, error) {
	documents, err := es.QuerySuggestByTitle(global.INDEX, info)
	return documents, err
}
